//
//  YGEnterTableViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/17.
//

#import "YGEnterTableViewCell.h"
#import "YGWeightManagerView.h"
#import "YGConsultView.h"
#import "YGOwnhelpView.h"
#import "YGFoodmanagerView.h"
#import "YGScienceCenterView.h"

@interface YGEnterTableViewCell ()

@property (nonatomic, strong) YGWeightManagerView *weightView;
@property (nonatomic, strong) YGConsultView *consultView;
@property (nonatomic, strong) YGOwnhelpView *helpView;
@property (nonatomic, strong) YGFoodmanagerView *foodView;
@property (nonatomic, strong) YGScienceCenterView *scienceView;








@end

@implementation YGEnterTableViewCell

#pragma private


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initContraints];
    }
    return self;
}

- (void)initView{

    [self addSubview:self.weightView];
    [self addSubview:self.consultView];
    [self addSubview:self.helpView];
    [self addSubview:self.foodView];
    [self addSubview:self.scienceView];
    
}

- (void)initContraints{
    [self.weightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(150);
        make.left.mas_equalTo(self.mas_left).offset(10);
        make.right.mas_equalTo(self.mas_right).offset(-10);
        make.top.mas_equalTo(self.mas_top).offset(-10);
    }];
    
    [self.consultView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.weightView.mas_bottom).offset(10);
            make.left.mas_equalTo(self.weightView.mas_left);
            make.width.mas_equalTo(175);
            make.height.mas_equalTo(100);
    }];
    
    [self.helpView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.weightView.mas_bottom).offset(10);
            make.left.mas_equalTo(self.consultView.mas_right).offset(5);
            make.width.mas_equalTo(175);
            make.height.mas_equalTo(100);
            make.right.mas_equalTo(self.weightView.mas_right);
    }];
    
    [self.foodView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.consultView.mas_bottom).offset(5);
            make.left.mas_equalTo(self.consultView.mas_left);
            make.width.mas_equalTo(175);
            make.height.mas_equalTo(100);
    }];
    
    [self.scienceView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.helpView.mas_bottom).offset(5);
            make.left.mas_equalTo(self.foodView.mas_right).offset(5);
            make.width.mas_equalTo(175);
            make.height.mas_equalTo(100);
            make.right.mas_equalTo(self.helpView.mas_right);
    }];
    
}

#pragma mark - foodmanagerView Delegate

//膳食管理跳转页面
- (void)foodViewInfoFoodMannagerAction{
    if ([self.delegate respondsToSelector:@selector(jumpFoodManagerPage)]) {
        [self.delegate jumpFoodManagerPage];
    }
}

-(void)ownHelpViewInfoOwnHelpControllerAction{
    if ([self.delegate respondsToSelector:@selector(jumpOwnHelpPage)]) {
        [self.delegate jumpOwnHelpPage];
    }
}

-(void)consultViewInfoConsultControllerAction{
    if ([self.delegate respondsToSelector:@selector(jumpConsultPage)]) {
        [self.delegate jumpConsultPage];
    }
}

-(void)scienceViewInfoScienceControllerAction{
    if ([self.delegate respondsToSelector:@selector(jumpConsultPage)]) {
        [self.delegate jumpScienceCenterPage];
    }
}


#pragma setter

- (YGWeightManagerView *)weightView{
    if (!_weightView) {
        _weightView = [[YGWeightManagerView alloc]init];
        _weightView.layer.cornerRadius=5;
        _weightView.clipsToBounds = YES;
       
    }
    return _weightView;
}

- (YGConsultView *)consultView{
    if (!_consultView) {
        _consultView = [[YGConsultView alloc]init];
        _consultView.consultViewDelegate = self;
    }
    return _consultView;
}

- (YGOwnhelpView *)helpView{
    if (!_helpView) {
        _helpView = [[YGOwnhelpView alloc]init];
        _helpView.ownHelpViewDelegate = self;
        
    }
    return _helpView;
}

- (YGFoodmanagerView *)foodView{
    if (!_foodView) {
        _foodView = [[YGFoodmanagerView alloc]init];
        _foodView.foodMannagerViewdelegate = self;
        
    }
    return _foodView;
}

- (YGScienceCenterView *)scienceView{
    if (!_scienceView) {
        _scienceView = [[YGScienceCenterView alloc]init];
        _scienceView.scienceViewDelegate = self;
        
    }
    return _scienceView;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    UIView *view = [super hitTest:point withEvent:event];
    if (view == nil) {

        if (CGRectContainsPoint(self.foodView.frame, point)) {
            view = self.foodView.foodBtn;
        }else if (CGRectContainsPoint(self.helpView.frame, point)){
            view = self.helpView.ownhelpBtn;
        }else if (CGRectContainsPoint(self.consultView.frame, point)){
            view = self.consultView.consultBtn;
        }else if (CGRectContainsPoint(self.scienceView.frame, point)){
            view = self.scienceView.scienceBtn;
        }

    }
    return view;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
